package com.bank.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置类 通过bean对象创建声明组件
 * 我们这里测试练习一个direct转发
 */
@Configuration
public class DeclareConfiguration {
    //声明queue 名字 queue_demo
    @Bean
    public Queue queueDemo() {
        Map<String,Object> args=new HashMap<>();
        args.put("x-expires",10000);
        return new Queue("queue_demo",false,false,false,null);
    }
    @Bean
    public Exchange exchangeDemo() {
        return new DirectExchange("direct_demo");
    }
    //绑定使用 demo_rk 路由key值
    @Bean
    public Binding bindingDemo() {
        //Binding.DestinationType.QUEUE 表示是队列绑定交换机
        return new Binding("queue_demo", Binding.DestinationType.QUEUE, "direct_demo", "demo_rk", null);
    }
}
